package mBio;

import java.io.*;
import java.util.*;
import rfBio.*;


public class get_columns {

	/**
	 * @param args
	 */
	public static void main(String[] args) 
						throws IOException, FileNotFoundException {
		// local variables
		blastm8 ref = new blastm8();
		blastm8 tempblast = new blastm8();
		Vector blastm8Vector = new Vector(100, 100);
		String o_filename = new String();
		String out_string = new String();



		// ***************************************************
		// read file section
		// ***************************************************
		
		// open ref_file
		BufferedReader refFile = new BufferedReader ( new FileReader (args[0]));
		
		// read ref_file line by line
		while (true){
			String line = refFile.readLine();
			if (line == null)
			{
				break;
			}			
			
			StringTokenizer ltok = new StringTokenizer(line, "\t");
			while ( ltok.hasMoreTokens() ){
				ref.set_query(ltok.nextToken());
				ref.set_subject(ltok.nextToken());
				ref.set_p1(Type.toFloat( ltok.nextToken() ));
				ref.set_allength(Type.toInt( ltok.nextToken() ));
				ref.set_p2(Type.toInt( ltok.nextToken() ));
				ref.set_p3(Type.toInt( ltok.nextToken() ));
				ref.set_qstart(Type.toInt( ltok.nextToken() ));
				ref.set_qstop(Type.toInt( ltok.nextToken() ));
				ref.set_sstart(Type.toInt( ltok.nextToken() ));
				ref.set_sstop(Type.toInt( ltok.nextToken() ));
				ref.set_evalue(Type.toFloat( ltok.nextToken() ));
				ref.set_score(Type.toInt( ltok.nextToken() ));		
			}
			
			blastm8Vector.add(new blastm8(ref));
		}
			
//		write output file
		o_filename = args[1];
		PrintWriter o_file = new PrintWriter(new BufferedWriter(new FileWriter(o_filename)));
		
		for(int i = 0; i < blastm8Vector.size(); i++){
			tempblast = (blastm8) blastm8Vector.get(i);
			out_string = "";
	
				if(Type.toInt(args[2])== 1){
					out_string = out_string + tempblast.get_query(); 		
				}
				if(Type.toInt(args[2])== 2){
					out_string = out_string + tempblast.get_query(); 		
				}
				if(Type.toInt(args[2])== 3){
					out_string = out_string + tempblast.get_p1(); 		
				}
				if(Type.toInt(args[2])== 4){
					out_string = out_string + tempblast.get_allength(); 		
				}
				if(Type.toInt(args[2])== 5){
					out_string = out_string + tempblast.get_p2(); 		
				}
				if(Type.toInt(args[2])== 6){
					out_string = out_string + tempblast.get_p3(); 		
				}
				if(Type.toInt(args[2])== 7){
					out_string = out_string + tempblast.get_sstart(); 		
				}
				if(Type.toInt(args[2])== 8){
					out_string = out_string + tempblast.get_sstop(); 		
				}
				if(Type.toInt(args[2])== 9){
					out_string = out_string + tempblast.get_qstart(); 		
				}
				if(Type.toInt(args[2])== 10){
					out_string = out_string + tempblast.get_qstop(); 		
				}
				if(Type.toInt(args[2])== 11){
					out_string = out_string + tempblast.get_evalue(); 		
				}
				if(Type.toInt(args[2])== 12){
					out_string = out_string + tempblast.get_score(); 		
				}
				o_file.print(out_string + "\n");
		}
		o_file.close();

		
	} // end main

}
